package com.example.gaoyang.controller;

import com.example.gaoyang.annotation.NoAuth;
import com.example.gaoyang.domain.request.PileLonLatRequest;
import com.example.gaoyang.domain.vo.PileLonLatVO;
import com.example.gaoyang.request.Result;
import com.example.gaoyang.service.PileLonLatService;
import com.example.gaoyang.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/pileLonLat")
public class PileLonLatController {

    @Resource
    private PileLonLatService pileLonLatService;

    @PostMapping("/add")
    public Result<Void> add(@RequestBody PileLonLatRequest request) {
        pileLonLatService.addPileLonLat(request);
        return ResultUtil.success();
    }

    @PostMapping("/list")
    @NoAuth
    public Result<List<PileLonLatVO>> list(@RequestBody PileLonLatRequest request) {
        return ResultUtil.success(pileLonLatService.getPileLonLatList(request));
    }

    @PostMapping("/update")
    public Result<Void> update(@RequestBody PileLonLatRequest request) {
        pileLonLatService.updatePileLonLat(request);
        return ResultUtil.success();
    }

    @PostMapping("/delete")
    public Result<Void> delete(@RequestBody PileLonLatRequest request) {
        pileLonLatService.deletePileLonLat(request);
        return ResultUtil.success();
    }

    @PostMapping("/getClosestPileLonLat")
    @NoAuth
    public Result<PileLonLatVO> getClosestPileLonLat(@RequestBody PileLonLatRequest request) {
        return ResultUtil.success(pileLonLatService.getClosestPileLonLat(request));
    }
}
